home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.beans.PropertyVetoException;
- import java.io.Serializable;
-
- public class DefaultDesktopManager implements DesktopManager, Serializable {
- static final String PREVIOUS_BOUNDS_PROPERTY = "previousBounds";
- static final String HAS_BEEN_ICONIFIED_PROPERTY = "wasIconOnce";
-
- public void activateFrame(JInternalFrame f) {
- Container p = ((Component)f).getParent();
- if (p == null) {
- p = f.getDesktopIcon().getParent();
- if (p == null) {
- return;
- }
- }
-
- Component[] c;
- if (p instanceof JLayeredPane) {
- JLayeredPane var10000 = (JLayeredPane)p;
- JLayeredPane var10001 = (JLayeredPane)p;
- c = var10000.getComponentsInLayer(JLayeredPane.getLayer(f));
- } else {
- c = p.getComponents();
- }
-
- int count = c.length;
-
- for(int i = 0; i < count; ++i) {
- if (c[i] != f && c[i] instanceof JInternalFrame) {
- JInternalFrame w = (JInternalFrame)c[i];
- if (w.isSelected()) {
- try {
- w.setSelected(false);
- } catch (PropertyVetoException var7) {
- }
- }
- } else if (c[i] instanceof JInternalFrame.JDesktopIcon && c[i] != f.getDesktopIcon()) {
- JInternalFrame w = ((JInternalFrame.JDesktopIcon)c[i]).getInternalFrame();
- if (w.isSelected()) {
- try {
- w.setSelected(false);
- } catch (PropertyVetoException var8) {
- }
- }
- }
- }
-
- f.moveToFront();
- }
-
- public void beginDraggingFrame(JComponent f) {
- }
-
- public void beginResizingFrame(JComponent f, int direction) {
- }
-
- public void closeFrame(JInternalFrame f) {
- if (((Component)f).getParent() != null) {
- Container c = ((Component)f).getParent();
- c.remove(f);
- ((Component)c).repaint(((JComponent)f).getX(), ((JComponent)f).getY(), ((JComponent)f).getWidth(), ((JComponent)f).getHeight());
- }
-
- this.removeIconFor(f);
- if (this.getPreviousBounds(f) != null) {
- this.setPreviousBounds(f, (Rectangle)null);
- }
-
- if (this.wasIcon(f)) {
- this.setWasIcon(f, (Boolean)null);
- }
-
- }
-
- public void deactivateFrame(JInternalFrame f) {
- }
-
- public void deiconifyFrame(JInternalFrame f) {
- JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
- if (((Component)desktopIcon).getParent() != null) {
- ((Component)desktopIcon).getParent().add(f);
- this.removeIconFor(f);
-
- try {
- f.setSelected(true);
- } catch (PropertyVetoException var3) {
- }
- }
-
- }
-
- public void dragFrame(JComponent f, int newX, int newY) {
- this.setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
- }
-
- public void endDraggingFrame(JComponent f) {
- }
-
- public void endResizingFrame(JComponent f) {
- }
-
- protected Rectangle getBoundsForIconOf(JInternalFrame f) {
- Rectangle p = ((Component)f).getParent().getBounds();
- Dimension prefSize = f.getDesktopIcon().getPreferredSize();
- int w2 = prefSize.width;
- int h2 = prefSize.height;
- int x2 = 0;
- int y2 = p.height - h2;
- if (((Component)f).getParent() == null && f.getDesktopIcon().getParent() == null) {
- return new Rectangle(x2, y2, w2, h2);
- } else {
- Container lp = ((Component)f).getParent();
- if (lp == null) {
- lp = f.getDesktopIcon().getParent();
- }
-
- int pos = lp.getComponentCount();
- lp.getComponents();
- int x3 = 0;
- int y3 = p.height;
-
- for(int i = pos - 1; i >= 0; --i) {
- JInternalFrame next = null;
- if (lp.getComponent(i) instanceof JInternalFrame) {
- next = (JInternalFrame)lp.getComponent(i);
- } else if (lp.getComponent(i) instanceof JInternalFrame.JDesktopIcon) {
- next = ((JInternalFrame.JDesktopIcon)lp.getComponent(i)).getInternalFrame();
- }
-
- if (next != null && next != f && this.wasIcon(next)) {
- Rectangle b = next.getDesktopIcon().getBounds();
- if (b.y < y3) {
- y3 = b.y;
- x3 = b.x + b.width;
- } else if (b.y == y3 && b.x + b.width > x3) {
- x3 = b.x + b.width;
- }
- }
- }
-
- if (y3 != p.height) {
- y2 = y3;
- }
-
- if (x3 + w2 > p.width) {
- y2 -= h2;
- x2 = 0;
- } else {
- x2 = x3;
- }
-
- return new Rectangle(x2, y2, w2, h2);
- }
- }
-
- protected Rectangle getPreviousBounds(JInternalFrame f) {
- return (Rectangle)((JComponent)f).getClientProperty("previousBounds");
- }
-
- public void iconifyFrame(JInternalFrame f) {
- JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
- if (!this.wasIcon(f)) {
- Rectangle r = this.getBoundsForIconOf(f);
- ((Component)desktopIcon).setBounds(r.x, r.y, r.width, r.height);
- this.setWasIcon(f, Boolean.TRUE);
- }
-
- Container c = ((Component)f).getParent();
- c.remove(f);
- c.add(desktopIcon);
- ((Component)c).repaint(((JComponent)f).getX(), ((JComponent)f).getY(), ((JComponent)f).getWidth(), ((JComponent)f).getHeight());
-
- try {
- f.setSelected(false);
- } catch (PropertyVetoException var5) {
- }
-
- }
-
- public void maximizeFrame(JInternalFrame f) {
- Rectangle p;
- if (!f.isIcon()) {
- this.setPreviousBounds(f, ((Component)f).getBounds());
- p = ((Component)f).getParent().getBounds();
- } else {
- Container c = f.getDesktopIcon().getParent();
- if (c == null) {
- return;
- }
-
- p = ((Component)c).getBounds();
-
- try {
- f.setIcon(false);
- } catch (PropertyVetoException var5) {
- }
- }
-
- this.setBoundsForFrame(f, 0, 0, p.width, p.height);
-
- try {
- f.setSelected(true);
- } catch (PropertyVetoException var4) {
- }
-
- this.removeIconFor(f);
- }
-
- public void minimizeFrame(JInternalFrame f) {
- if (this.getPreviousBounds(f) != null) {
- Rectangle r = this.getPreviousBounds(f);
- this.setPreviousBounds(f, (Rectangle)null);
-
- try {
- f.setSelected(true);
- } catch (PropertyVetoException var4) {
- }
-
- if (f.isIcon()) {
- try {
- f.setIcon(false);
- } catch (PropertyVetoException var3) {
- }
- }
-
- this.setBoundsForFrame(f, r.x, r.y, r.width, r.height);
- }
-
- this.removeIconFor(f);
- }
-
- public void openFrame(JInternalFrame f) {
- if (f.getDesktopIcon().getParent() != null) {
- f.getDesktopIcon().getParent().add(f);
- this.removeIconFor(f);
- }
-
- }
-
- protected void removeIconFor(JInternalFrame f) {
- JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
- Container c = ((Component)di).getParent();
- if (c != null) {
- c.remove(di);
- ((Component)c).repaint(((JComponent)di).getX(), ((JComponent)di).getY(), ((JComponent)di).getWidth(), ((JComponent)di).getHeight());
- }
-
- }
-
- public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
- this.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
- }
-
- public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
- boolean didResize = f.getWidth() != newWidth || f.getHeight() != newHeight;
- ((Component)f).setBounds(newX, newY, newWidth, newHeight);
- if (didResize) {
- ((Container)f).validate();
- }
-
- }
-
- protected void setPreviousBounds(JInternalFrame f, Rectangle r) {
- if (r != null) {
- ((JComponent)f).putClientProperty("previousBounds", r);
- }
-
- }
-
- protected void setWasIcon(JInternalFrame f, Boolean value) {
- if (value != null) {
- ((JComponent)f).putClientProperty("wasIconOnce", value);
- }
-
- }
-
- protected boolean wasIcon(JInternalFrame f) {
- return ((JComponent)f).getClientProperty("wasIconOnce") == Boolean.TRUE;
- }
- }
-